PDA

View Full Version : VBA : Input form : Copy column and paste special value in another column



Steenbok
10-11-2023, 07:12 AM
Hello


I'm quite new to VBA .
I'm trying to do a Input form with VBA


I have 3 sheets

Sheet1 : Input
Sheet 2 : Sheet3
Sheet 3 : Cal

I have two macros which work with a insert button :


Sheet1 = Input - Sub OneCell()
Sheet2 = Sheet3 - Sub ok()



Sub OneCell()
Sheets("Input").Range("c3:c9").Copy Sheets("Sheet3").Range("b3:b9")
Sheets("Input").Range("c3:c9").ClearContents
End Sub


and


Sub ok()
Sheets("Sheet3").Range("c3:c9").Copy
Sheets("Cal").Range("c3:c9").PasteSpecial Paste:=xlPasteValues
Sheets("Sheet3").Range("b3:b9").ClearContents
End Sub


For the Macro Sub ok(), I would like to have the same code but which will paste the value in the the following empty columns in Sheet Cal
such as pasting the values starting in c3:c9 then pasting the following values in d3:d9 and so on

Is what something possible ?


Thanks in advance

June7
10-11-2023, 10:35 AM
Please post code between CODE tags to retain indentation and readablity. Use # icon on edit toolbar.

Sure, most anything is possible. But I don't quite understand the "following values in d3:d9 and so on" requirement. What are "following values" and what is meant by "and so on". Perhaps you should attach file and include a sheet that shows what you result you want.

Aussiebear
10-11-2023, 01:01 PM
Welcome to VBAX Steenbok. When posting code to this forum, please wrap your code with code tags. See the first line in my signature as a hint to as how this is done.

Aussiebear
10-11-2023, 01:06 PM
@June7. I think that Steenbok is wanting to paste the next lot of information in the next column over.

georgiboy
10-11-2023, 10:39 PM
Will the below help?


Sub ok()
Sheets("Sheet3").Range("c3:c9").Copy
Sheets("Cal").Cells(3, Columns.Count).End(xlToLeft).Offset(, 1).PasteSpecial xlValues
Sheets("Sheet3").Range("b3:b9").ClearContents
End Sub