qwertytrewq
New Member
- Joined
- Apr 19, 2018
- Messages
- 9
I have a small vba code to copy data to another sheet - (data from SampleSheet1 {range(B17:W*) *is obtained from cell AA17} to SampleSheet2 {range(no change from last selected)}
The problem is command at 'point2 executes before the command at 'point1
i.e. the "Pagedown" key gets pressed at "SampleSheet1" and not on sheet "SampleSheet2"
also the macro results in weird "NumLock" off/on execution. i.e. the macro results in "NumLock" turning off if its on and viceversa.
Thanks in advance for giving this problem your precious time.
Code:
Dim Cval As Variant
Dim Rng1 As Range
Worksheets("SampleSheet1").Activate
Cval = ActiveSheet.Range("AA17").Value + 16
Set Rng1 = ActiveSheet.Range("B17:W" & Cval)
Rng1.Copy
Worksheets("SampleSheet2").Activate
Selection.PasteSpecial Paste:=xlPasteValues
Selection.PasteSpecial Paste:=xlPasteFormats 'point1:warning:
Application.SendKeys "^{PGDN}", True
Application.CutCopyMode = False
Worksheets("SampleSheet1").Activate 'point2:warning:
End Sub
The problem is command at 'point2 executes before the command at 'point1
i.e. the "Pagedown" key gets pressed at "SampleSheet1" and not on sheet "SampleSheet2"
also the macro results in weird "NumLock" off/on execution. i.e. the macro results in "NumLock" turning off if its on and viceversa.
Thanks in advance for giving this problem your precious time.
Last edited by a moderator: