Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
237 views
in Technique[技术] by (71.8m points)

vba excel: How to fill in two cells in a row with text

I need to make a header in my excel sheet using VBA. Seems pretty simple, but when I do this

Worksheets("New_Students").Range("A1").Value = "studentID"
Worksheets("New_Students").Range("B1").Value = "ISUID"

only the first line works and not the second one. What am I forgetting?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try this:

  1. Inside the excel application go to the developer tab on the ribbon and click record macro.
  2. Type the values into the two cells manually.
  3. Click stop recording and view the macro it created.

This would show you VBA code that will work and you can compare it to what you have in order to trouble shoot.

This is called recording a macro and can be very helpful in solving problems. In fact I would suggest doing so almost every time before asking a question here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...