View Single Post
 
Old 12-07-2013, 12:05 AM
BobBridges's Avatar
BobBridges BobBridges is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: May 2013
Location: USA
Posts: 700
BobBridges has a spectacular aura aboutBobBridges has a spectacular aura about
Default

Right, sorry, A4 is where the button is; I forgot. Yes, let's go over it step by step; but plan on it taking a while, because if you've never done a VBA program before it'll take you a while to learn the pieces.

So let's start here: You're about to create an Excel macro, a program in the VBA language. Do you know where to type in your statements? If you don't, we need to start there. If you do, here are the first few statements:
Code:
Sub Something() 'I don't care what you name it.
  Set wo = ThisWorkbook
  Set soFm = wo.Worksheets("Page1")
  snTo = soFm.Range("A1").Value
  MsgBox snTo
  End Sub
This very simple little program does the following:

1) Sets a variable called "wo" to point to the current workbook; that allows you to refer to it later.

2) Sets a variable called "soFm" to point to the worksheet in wo that is named "Page1". If that's not what you named the first worksheet, change it in the program. I named that variable "soFm" because the "so" prefix means "sheet object" to me, and "Fm" means "From"—that is, the sheet that the data is going to be transferred from.

3) Looks at Page1!A1, and puts the contents of that cell into a variable named snTo ("sheet name To"), which is the name of the worksheet where you want the data to be cut and pasted to.

4) Displays that name to you in a message window. By the time you're done writing this program, you don't want it to display the name of the sheet, you just want the program to transfer the data; but this is a good place to write that message and test the program so you can see that it's working so far. But don't worry, it's not done yet.

Try that, and tell me whether it's working right. If not, then we need to go back and figure out what's not going right.
Reply With Quote