Problem assigning values

51DegreesNorth

New Member
Joined
Mar 29, 2022
Messages
11
Office Version
  1. 365
Platform
  1. Windows
The application I'm working on must keep two rows in sync. These rows live on two different sheets within one workbook.
I can do the sync using select and copy/paste, but I'm looking for a much faster way.
VBA Code:
Sub Alt_Copy()

Dim Src_PO_Nr As Long
Dim FindRow As Long

Src_PO_Nr = 5
FindRow = 10

'this line of code gets executed
ThisWorkbook.Sheets("B").Range(Cells(FindRow, 1), Cells(FindRow, 41)).Value = 10

'this one causes error 1004 - but they are basically the same !
ThisWorkbook.Sheets("A").Range(Cells(Src_PO_Nr, 1), Cells(Src_PO_Nr, 41)).Value = 20

End Sub

I'd like to end up with just one statement in the form "Range.Value=Range.value" .
What is going on here ? What am I missing ?
Thank you.
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
That line works fine in the activesheet, and that is "B".
If your activesheet was "A", the 1st line 'll give an error, the 2nd not !
Learn the features of offset and resize !
VBA Code:
this line of code gets executed
ThisWorkbook.Sheets("B").Cells(FindRow, 1).Resize(, 41).Value = 10

'this one causes error 1004 - but they are basically the same !

ThisWorkbook.Sheets("A").Cells(Src_PO_Nr, 1).Resize(, 41).Value = 20
 
Upvote 0
Solution
Fast and spot on, thank you very much ! I think I see what the effect of resizing is and I'll certainly have a thorough look at that.
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,369
Members
449,080
Latest member
Armadillos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top