[RESOLVED] Dim and Copy and Paste issue in VBA
I am getting a few errors when I try to run this. I have a secret suspicion that I am missing something super simple.
Code:
Sub StatSig()
Dim FirstSht As Worksheet
ActiveSheet.Name = FirstSht
Dim StatSigSht As Worksheet
Sheet23 = StatSigSht
FirstSht.Range("B61:C62").Value = StatSigSht.Range("D19:E20").Value
StatSigSht.Range("D27").Value = FirstSht.Range("B71").Value
StatSigSht.Range("C29").Value = FirstSht.Range("B72").Value
End Sub
Help me out!
Re: Dim and Copy and Paste issue in VBA
as well as declare the sheet you also have to set the object to the variable
try like, below, but i am guessing if this is the desired requirement
vb Code:
Dim FirstSht As Worksheet
set FirstSht = activesheet
Dim StatSigSht As Worksheet
Set StatSigSht = sheets("sheet23")
FirstSht.Range("B61:C62").Value = StatSigSht.Range("D19:E20").Value
StatSigSht.Range("D27").Value = FirstSht.Range("B71").Value
StatSigSht.Range("C29").Value = FirstSht.Range("B72").Value
Re: Dim and Copy and Paste issue in VBA
You have to assign something to the worksheets you dim.
Code:
Sub StatSig()
Dim FirstSht As Worksheet
Set FirstSht = Worksheets("NAMEHERE")
ActiveSheet.Name = FirstSht
Dim StatSigSht As Worksheet
Set StatSigSht = Worksheets("NAMEHERE")
Sheet23 = StatSigSht
FirstSht.Range("B61:C62").Value = StatSigSht.Range("D19:E20").Value
StatSigSht.Range("D27").Value = FirstSht.Range("B71").Value
StatSigSht.Range("C29").Value = FirstSht.Range("B72").Value
End Sub
Re: [RESOLVED] Dim and Copy and Paste issue in VBA
Thanks for the help on that. That was super simple!
Re: [RESOLVED] Dim and Copy and Paste issue in VBA
So I may have clicked Resolved a little too soon. I have to go back to the initial sheet and paste other info. Does anyone have a simple idea on how to address this? It's telling me the String isn't working.
Code:
Sub StatSig()
Dim strInitialCellAddress As String
strInitialCellAddress = ActiveCell.Address
ActiveSheet.Range("B61:C62").copy
Sheets("Inputs & Outputs").Select
ActiveSheet.Range("D19:E20").PasteSpecial xlPasteValues
ActiveSheet.Range("D27").copy
strInitialCellAddress.Select
ActiveSheet.Range("B71").PasteSpecial xlPasteValues
strInitialCellAddress.Select
ActiveSheet.Range("C29").copy
strInitialCellAddress.Select
ActiveSheet.Range("B72").PasteSpecial xlPasteValues
End Sub
Re: [RESOLVED] Dim and Copy and Paste issue in VBA
your first code using sheet objects to work with multiple sheets, is far superior to selecting and using activesheet, as far as possible, avoid selection, select and active anything in your code