Above cell

[Solved/Closed]
Report
-
Posts
2
Registration date
Tuesday April 21, 2009
Status
Member
Last seen
April 23, 2009
-
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

Posts
7098
Registration date
Saturday April 7, 2007
Status
Moderator
Last seen
June 10, 2021
487
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
Posts
2
Registration date
Tuesday April 21, 2009
Status
Member
Last seen
April 23, 2009

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
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
> WutUp WutUp
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
Posts
7098
Registration date
Saturday April 7, 2007
Status
Moderator
Last seen
June 10, 2021
487
Hi,
Arff, sorry for my misunderstanding, fortunately WutUp WutUp gave you the solution.
Have a nice day
Posts
2
Registration date
Tuesday April 21, 2009
Status
Member
Last seen
April 23, 2009

Good Morning to all,Great, with some minor changes to cutomize it, the solution from WutUp is the solution, thanks, it works great.