Cannot execute multiple Range in a Sub

techissue2008

Board Regular
Joined
Jun 13, 2008
Messages
80
Hi

I tried the following code but it shows an error:

Code:
Sub test2col()
Sheets("Sheet6").Cells.ClearContents
Sheets("Sheet6").Range("A:B").Value = Sheets("Sheet1").Range("A:B").Value
Sheets("Sheet6").Range("D").Value = Sheets("Sheet1").Range("C").Value
End Sub

It said
Code:
Sheets("Sheet6").Range("D").Value = Sheets("Sheet1").Range("C").Value
End Sub

has error.

Does a Sub not support to use Range more than one time? If so, do I need to write many Sub to do it?

Thanks for advance.
 
_ is used to cut long lines of code in smaller parts, this is purely functional so you can show the code in one window without having to scroll from left to right.

E.g.
Code:
Dim Text as String

String = "As you can see this string is very very very very very very very very" _
"very very very long and therefore i cut this into pieces"

:= is used (correct me if I'm wrong, other readers) for commands that use multiple arguments, like for example msgbox.
You can use Msgbox in multiple ways:

Code:
' Like this

Msgbox "Beep - messagebox!"

'Or

Msgbox("Beep - messagebox!",vbOK)

'Or

Msgbox Prompt:="Beep - messagebox!" Buttons:=vbOK

Not 100% sure of the syntax on that last one, but should give you an idea of what it does.
 
Last edited:
Upvote 0

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

Forum statistics

Threads
1,215,443
Messages
6,124,890
Members
449,194
Latest member
JayEggleton

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