Home |
Search |
Today's Posts |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
When you use Cells(X,Y) to refer to a range, the X represents the row and the Y
represents the column. And rows are numbered (1, 2, ..., 65536) and columns are usually lettered (A, B, ...., IV) <but there's a setting that can show numbers (1, 2, ..., 256). And this won't work: Rows("j:j").Select But if you could use: rows(j & ":" & j).select or even rows(j).select But it's not necessary to select most things to work with them. I wasn't sure what column contained the key value, so I guessed column A. Try this against a copy of the worksheet. Option Explicit Sub testme() Dim wks As Worksheet Dim FirstRow As Long Dim LastRow As Long Dim iRow As Long Set wks = Worksheets("sheet1") With wks FirstRow = 2 'headers in 1 LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row For iRow = LastRow To FirstRow + 1 Step -1 If .Cells(iRow, "A").Value = .Cells(iRow - 1, "A").Value Then 'do nothing Else .Rows(iRow).Resize(2).Insert .Rows(1).Copy _ Destination:=.Cells(iRow + 1, "A") End If Next iRow End With End Sub Tom Fortune wrote: Have have rows of data for deviations. I sort by Close date and delete all rows that have been closed. I then sort by department. What i want to do next is insert a blank row and copy the first row in the first row so that it is easy to cut and paste the data for each department and email to those departments. I'm having trouble with an if statement that compares the active cell with the next or previous (which ever is easiest), and if they are different, insert the blank and header. The blank row is not abosilutely necessary. It just helps to cut and paste into the email. This is what I was trying: Dim cRowsB As Integer Dim j As Integer cRowsB = Cells(Rows.Count, 2).End(xlUp).Row Range("G3").Select For j = 3 To cRowsB If Cell(G, j).Value = Cell(G, j - 1).Value Then Rows("j:j").Select Selection.Insert Shift:=xlDown Rows("1:1").Select Selection.Copy Rows("j:j").Select Selection.Insert Shift:=xlDown Selection.Paste ActiveCell.Offset(1, 0).Select End If Next j Thanks for any help. I'm a really not good at VB. "Dan Gardner" wrote: "Tom Fortune" wrote: After sorting, how is the best way to compare two adjacent cells in a column, and if they are different, insert a blank row and a header row between them. -- Sincerely, Tom Fortune Tom, Not completely sure about the question, but to insert rows and clolumns you can use the following code Rows("XX:XX").Select Selection.Insert Shift:=xlDown Columns("XX:XX").Select Selection.Insert Shift:=xlToRight as for reading cells workbooks("XXXXX").worksheets("XXXXXX").cells(XX, XX).value or if your not changeing workbooks and/or worksheets then just simple cells(XX, XX).value works if this isn't mutch help you can always record a macro of you doing what you want to do and then view and edit the code to fit your needs -- Dave Peterson |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
compare 2 column cells and return the adjacent columns cells data of the cell | Excel Worksheet Functions | |||
Compare 1 cell to column of cells returning adjacent cells info? | Excel Worksheet Functions | |||
Need a insert a empty cell if compare different function | Excel Discussion (Misc queries) | |||
How do I compare cells and if FALSE compare to next cell in EXCEL | Excel Worksheet Functions | |||
Compare 2 cells in 2 worksheets, rewrite one of the cells | Excel Programming |