Hi,
The fastest way to get where you want to go is to take one step at a time. Put each step into its own thread and don't let go until you got what you wanted. Then turn to the next problem. (You can run several threads side by side, though, for as many as you can keep track of.)
1. The Macro recorder automatically guides you toward Copy / Paste:
- Code: Select all
Range("A1").Select
Selection.Copy
Range("B2").Select
ActiveSheet.Paste
Actually, this isn't the way Excel thinks at all. Instead, it deals with what Excel does as well as what you see. When you write code you can neglect the second part and you end up with much shorter code, like this:
- Code: Select all
Range("A1") = Range("A2")
2. The default property of a range is its Value. Because it is the default it doesn't need to be written, though most teachers recommend that you do. Anyway, in the above code the Value of A2 is written to the Value property of A1. It seems, you wanted the cell reference to be written instead. The property required is the Address. This code will write the cell reference to A1:
- Code: Select all
Range("A1").Formula = "=" & Range("A2").Address
As you see, you didn't write to the default property (Value) of A1. Instead, you wrote to another property, the Formula property. And, since the Address of A2 is "$A$2" isn't a valid formula without the "=" before it, you added that and concatenated the two strings with an ampersand. If you don't need the (default) absolute referencing you can modify the address you write any way you want, but that is another thread unless you find it in the Help.
3. When you copy and paste merged cells the two ranges must be of identical size. If you refer to merged cells by their range address you should remember that only their top-left cell has the value or formula. So, to get the Value of range A1:B2 you ask the Value of A1. B2 has no value and may cause an error. Similarly, you can write the value of A1:B2 by writing to A1. The important thing is to avoid Copy / Paste, as the macro recorder would have you do, and use Read / Write instead, as demonstrated in the above code.
4. Your final question seems unclear, because what could possibly be difficult about having a cell into which you write the name of a tab, unless it is the abundance of cells to choose from? I presume that what you had in mind was a little more sophisticated. Perhaps this fragment of code can help you on your way:
- Code: Select all
Activesheet.Cells(1, 1).Value = ActiveSheet.Name
I trust that you can actually understand this code even though it uses language you won't get from the Recorder. To manipulate this code you need to know the following:
a) You can replace Activesheet with Worksheets("Sheet name") or Worksheets(1)
b) The Cell address is defined by Row and Column, in that sequence, where Column 1 = A, 2 = B etc.
See what I mean? You got a lot of well-meant and very interesting advice. As such, you are now better equipped to deal with your problems than before. But has any one of them gone away as a result of your post?