Thread Closed

Small Coding Problem for Excel Macro

 
Share Thread Thread Tools
Jul2-10, 06:08 PM   #1
 

Small Coding Problem for Excel Macro


I want to code a macro that will take in an integer as a row number and insert two rows above that row. This will repeat in a for loop. The problem is that I'm not familiar with VB syntax. Here's what I have so far:

Sub Insert_Rows_Loop()
Dim CurrentSheet As Object
Dim x As Integer

' Loop through all selected sheets.
For Each CurrentSheet In ActiveWindow.SelectedSheets
For x = 14 To 418
' Insert 2 rows depending on values of a1 and a2.
CurrentSheet.Range("a" & x &:"a" & (x+1)&").EntireRow.Insert
Next x
Next CurrentSheet
End Sub

There is some sort of syntax error in the CurrentSheet.Range argument. How does one specify a range with a variable?

Thanks.
PhysOrg.com
PhysOrg
science news on PhysOrg.com

>> Ants and carnivorous plants conspire for mutualistic feeding
>> Forecast for Titan: Wild weather could be ahead
>> Researchers stitch defects into the world's thinnest semiconductor
Jul4-10, 11:45 AM   #2
 
Try this...

CurrentSheet.Range("a" & x & ":a" & (x+1)).EntireRow.Insert
Jul8-10, 09:58 PM   #3
 
Thanks, but that just deleted everything :) I found another macro to use.
Thread Closed

Tags
excel, macro, visual basic
Thread Tools


Similar Threads for: Small Coding Problem for Excel Macro
Thread Forum Replies
Thermodynamics / micro/macro connection problem Introductory Physics Homework 4
IFORT Coding Problem (Simpson's Rule) Engineering, Comp Sci, & Technology Homework 3
Cell formula promlem - Excel macro Programming & Comp Sci 2
Excel Problem Computing & Technology 3
Sort and format a protected Excel worksheet with a macro Computing & Technology 0