Search : in
By :

Above cell

Last answer on Apr 23, 2009 3:13:21 pm BST motorsito, on Apr 22, 2009 7:12:32 pm BST 
 Report this message to moderators

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.

Best answers for « above cell » in :
Spreadsheets - Cell Selection Show Cell Selection Spreadsheets are powerful tools for working with data. However, to work with data, it is necessary to have tools to rapidly choose the required cells. Line Selection An entire line can be chosen by clicking directly on the line...
Excel tips : How to insert date in a cell Show Excel tips : How to insert date in a cell Below are some tips on how to insert date and time in an excel cell for a specific purpose:- To insert current date, press CTRL + ; in the chosen cell. To insert current time, press CTRL+...
[VBA] Detecting changes in cell Show [VBA] Detecting changes in cell The Event Change feature of a sheet will detects the change in the active cell but it gives no information about the content. The example given below will help you to find out if the cell was changed,...
[VBA] Deleting a word in a range of cell Show[VBA] Deleting a word in a range of cell In the case you want to delete a word in a sentence, just create a small macro that removes the word. But it will become difficult when you have word like, for example, "Theword" or "THEWORD" or...
Excel – Comparing cell A1 to entire A column in Sheet 2 ShowExcel – Comparing cell A1 to entire A column in Sheet 2 Issue Solution Note Issue I have been trying to compare sheet1 A2 to sheet2 A2 through A500 and if it exists somewhere in sheet2's a col then copy that entire row to a new sheet....
Repainting a cell using excel VBA ShowRepainting a cell using excel VBA Issue Solution Note Issue I am writing a code in excel VBA to generate a report.I am totally new to VBA.Here's my code Private Sub CommandButton1_Click() Dim a1 As Integer Dim d1 As Integer Dim...
Download USA Unlisted Cell Phone Numbers ShowHas you friend flown for America without telling you where he/she would settle? Don’t panic! USA Unlisted Cell Phone Numbers is a program which can help you. By using this program, you simply need to know his/her phone number in order to find...
Worksheet - Cells ShowThe Concept of a Cell A "cell" is the intersection between a line (horizontal) and a column (vertical) on a worksheet. Thus, the name of the line combined with the name of the column gives the cell's coordinates (the term address is sometimes also...
Spreadsheet - Text Operators ShowConcatenation Operator Spreadsheets generally use an oeprator, called a concatenation operator , that allows two text values to be added together. The concatenation operator, written as &, is used as follows: In the above example, the cell...

1

aquarelle, on Apr 22, 2009 8:28:23 pm BST

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 "Pour trouver une solution � ses probl�mes, il faut s'en donner la peine."

Reply to aquarelle

2

motorsito, on Apr 22, 2009 10:04:11 pm BST

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

Reply to motorsito

3

WutUp WutUp, on Apr 23, 2009 12:29:51 am BST
  • +1

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

Reply to WutUp WutUp

4

WutUp WutUp, on Apr 23, 2009 12:35:10 am BST

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

Reply to WutUp WutUp

5

aquarelle, on Apr 23, 2009 1:37:35 pm BST

Hi,
Arff, sorry for my misunderstanding, fortunately WutUp WutUp gave you the solution.
Have a nice day "Pour trouver une solution � ses probl�mes, il faut s'en donner la peine."

Reply to aquarelle

6

 motorsito, on Apr 23, 2009 3:13:21 pm BST

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

Reply to motorsito