Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default row insert problem

I have this code, its all ok unitl the last if part.

I'm trying to add a number of rows at the bottom populated row depend on the
number in J and last cell.

any help cheers?

Sub InsertDataintoBlank()

IngLastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row

For lngRow = 1 To lngLastRow
If Trim(Range("A" & lngRow)) < "" Then
strData = Range("A" & lngRow)
Else
Range("A" & lngRow) = strData
End If
Next

If Range("A" & IngLastRow).Value 0 Then

Rows(IngLastRow, IngLastRow + (Range("J" & IngLastRow).Value)).Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove

Else
End If

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default row insert problem

Two things:

1. This line has a typo:

For lngRow = 1 To lngLastRow

It has a lower case L instead of upper case I (i). Use courier font to
detect.

2. This line:

Rows(IngLastRow, IngLastRow + (Range("J" & IngLastRow).Value)).Select

Change to:

Rows(IngLastRow & ":" & IngLastRow + (Range("J" & IngLastRow).Value)).Select

This assumes that there is an integer value in the cell in column J.

"project manager" wrote in
message ...
I have this code, its all ok unitl the last if part.

I'm trying to add a number of rows at the bottom populated row depend on
the
number in J and last cell.

any help cheers?

Sub InsertDataintoBlank()

IngLastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row

For lngRow = 1 To lngLastRow
If Trim(Range("A" & lngRow)) < "" Then
strData = Range("A" & lngRow)
Else
Range("A" & lngRow) = strData
End If
Next

If Range("A" & IngLastRow).Value 0 Then

Rows(IngLastRow, IngLastRow + (Range("J" & IngLastRow).Value)).Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove

Else
End If

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default row insert problem

Hi, I have missed the declaration part in my original code...I use to prefix
the variables like the below....Use the below code to modify.. Also use
Option Explicit to avoid such issues. If you are looking to continue the
filling upto the value mentioned in Col J say (J1) you can straight away
replace the first line in the code to say lngLastRow = Range("J1")....Cheers
"Project Manager"..

lng for Long
int for Integer
str for String
bln for Boolean and so on..........

Option Explicit

Dim lngRow as Long
Dim lngLastRow as Long
Dim strData as String

lngLastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row

For lngRow = 1 To lngLastRow
If Trim(Range("A" & lngRow)) < "" Then
strData = Range("A" & lngRow)
Else
Range("A" & lngRow) = strData
End If
Next



If this post helps click Yes
---------------
Jacob Skaria


"project manager" wrote:

I have this code, its all ok unitl the last if part.

I'm trying to add a number of rows at the bottom populated row depend on the
number in J and last cell.

any help cheers?

Sub InsertDataintoBlank()

IngLastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row

For lngRow = 1 To lngLastRow
If Trim(Range("A" & lngRow)) < "" Then
strData = Range("A" & lngRow)
Else
Range("A" & lngRow) = strData
End If
Next

If Range("A" & IngLastRow).Value 0 Then

Rows(IngLastRow, IngLastRow + (Range("J" & IngLastRow).Value)).Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove

Else
End If

End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert Row Problem george Excel Programming 4 March 31st 06 03:27 PM
Insert Rows Problem comotoman Excel Discussion (Misc queries) 3 October 7th 05 05:20 PM
Insert Function Problem zero635[_3_] Excel Programming 5 July 18th 05 08:54 PM
insert row problem WYN Excel Discussion (Misc queries) 3 June 30th 05 05:46 AM
Insert Code Problem pwz Excel Programming 2 July 7th 04 05:49 AM


All times are GMT +1. The time now is 02:26 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"