Above cell

Solved/Closed
motorsito - Apr 22, 2009 at 02:12 PM
motorsito Posts 2 Registration date Tuesday April 21, 2009 Status Member Last seen April 23, 2009 - Apr 23, 2009 at 10:13 AM
I get a large database every week in which I have to insert a row every row different than the one above, it is a tedeous task that takes me hours, I've been working with macros for over 7 years now and I just can't figure this one out, can some one help please, all I need is to know how to put the frase "different than above" in VBA terms.
At first I thought it would be easy to use the offset procedure but to make the comparisson between the active cell and the one above is breaking me up.

3 replies

aquarelle Posts 7118 Registration date Saturday April 7, 2007 Status Moderator Last seen July 29, 2022 491
Apr 22, 2009 at 03:28 PM
Hi,

1) Next time, it would be a good idea to salute people who could help you, OK ? ;)

2) Concerning your problem to write "different than above" in VBA, you just have to use <>
For example :
If Cell <> "0" then ...

Hope this help you.

Best regards
0
motorsito Posts 2 Registration date Tuesday April 21, 2009 Status Member Last seen April 23, 2009
Apr 22, 2009 at 05:04 PM
Hi there, sorry for the lack of manners in the previous post, I apologize.
regarding yourtip, is helpful, no doubt, but it's not that simple, remember I need the whole frase "diferent than above", I know tha <> means "diferent than".
for example:for each c. in range("a1:a2000")
if c.value <> (here I need the frase"than above")then
selection.entirerow. insert
enf if
next
0
Maybe this will get you in the right direction.
Hope this helps!


Private Sub InsertRow()

Dim LastRow As Integer
Dim intRow As Integer

LastRow = Cells(Rows.Count, 1).End(xlUp).Row


For intRow = LastRow To 2 Step -1

Rows(intRow).Select
If Cells(intRow, 1).Value <> Cells(intRow, 1).Offset(-1, 0).Value Then
Cells(intRow, 1).Select
Selection.EntireRow.Insert

End If

Next intRow


Range("A1").Select

End Sub
0
WutUp WutUp > WutUp WutUp
Apr 22, 2009 at 07:35 PM
Sorry, remove "Private" before Sub. I coded it in a command button first.

Sub InsertRow()

Dim LastRow As Integer
Dim intRow As Integer

LastRow = Cells(Rows.Count, 1).End(xlUp).Row


For intRow = LastRow To 2 Step -1

Rows(intRow).Select
If Cells(intRow, 1).Value <> Cells(intRow, 1).Offset(-1, 0).Value Then
Cells(intRow, 1).Select
Selection.EntireRow.Insert

End If

Next intRow

Range("A1").Select

End Sub
0
aquarelle Posts 7118 Registration date Saturday April 7, 2007 Status Moderator Last seen July 29, 2022 491
Apr 23, 2009 at 08:37 AM
Hi,
Arff, sorry for my misunderstanding, fortunately WutUp WutUp gave you the solution.
Have a nice day
0
motorsito Posts 2 Registration date Tuesday April 21, 2009 Status Member Last seen April 23, 2009
Apr 23, 2009 at 10:13 AM
Good Morning to all,Great, with some minor changes to cutomize it, the solution from WutUp is the solution, thanks, it works great.
0