0

I'm trying to create a macro to copy and paste a certain section of a row to another sheet. I'm getting the user to input the row they want the copy/paste to work from.

I've created a variable (Dim c) for the user to input the row value, and want to use that variable in a range, but don't know how.

E.g.

Range("C5:I5").Copy Range("C45:I45")

In the first step of this I want the '5' to be replaced by variable c, but how do I call that variable in this statement?

Tried Range("C(Val(c)):I(Val(c))"), but that hasn't worked.

Apologies for rookie errors, but I'm fairly new to VBA.

GSerg
  • 76,472
  • 17
  • 159
  • 346
NightM0de
  • 11
  • 1
  • 3
  • Try `Dim c As Long`, followed by `c = 5` then use `Range("C" & c & ":I" & c).Copy Range("C45:I45")`. – FaneDuru Feb 06 '23 at 11:27

1 Answers1

0

Got it eventually using this -

Range("C" & c & ":I" & c)

NightM0de
  • 11
  • 1
  • 3
  • What did you try with this pseudo answer? Did you copy the solution from my comment, placed three minutes before it? – FaneDuru Feb 06 '23 at 12:26
  • @FaneDuru I found it on the web, the came back and posted. Your response probably didn't show up for me before I posted, because I hadn't refreshed. – NightM0de Feb 06 '23 at 15:14
  • I can accept that... Anyhow, your question has been closed. – FaneDuru Feb 06 '23 at 15:17