Data Record ID#

KDS14589

Board Regular
Joined
Jan 10, 2019
Messages
182
Office Version
  1. 2016
Platform
  1. Windows
Excuse the code if it cumbersome but I’m still learning.

I’m trying to generate a ID# record number for a row with data in the col_data fields, blank rows would show nothing.

ID#’s would be placed in the 3rd column and identical values placed 2 columns to the right of the col_data_last on the same row.

This code works but only for the first record but I have several hundred more to go. Each record row can have both text and numeral fields.

Can someone HELP me get past the first row or suggest a better way to get the same results.



Code:
''''record id#

For row_data = row_data_start To row_data_last + 1

For col_data = col_data_start To col_data_last

If Not IsEmpty(Cells(row_data, col_data)) Then

Cells(row_data, 3).Value = "ID# " & Format(Val(row_data - row_data_start) + 1, "0000-" & UCase(Mid(ws.Range("A4"), _

(Application.WorksheetFunction.Find(".", ws.Range("A4"), 1) + 1), 3)))

Cells(row_data, col_data_last + 2).Value = "ID# " & Format(Val(row_data - row_data_start) + 1, "0000-" & UCase(Mid(ws.Range("A4"), _

(Application.WorksheetFunction.Find(".", ws.Range("A4"), 1) + 1), 3)))

Cells(row_data, 3).Interior.Color = RGB(205, 128, 114) 'salmon

Cells(row_data, col_data_last + 2).Interior.Color = RGB(205, 128, 114) 'salmon

Cells(row_data, 3).Borders.LineStyle = xlContinuous

Cells(row_data, col_data_last + 2).Borders.LineStyle = xlContinuous

Else

Cells(row_data, 3).Value = ""

Cells(row_data, col_data_last + 2).Value = ""

Cells(row_data, 3).Interior.Color = RGB(154, 205, 50) 'yellow green

Cells(row_data, col_data_last + 2).Interior.Color = RGB(154, 205, 50) 'yellow green

Cells(row_data, 3).Borders.LineStyle = xlNone

Cells(row_data, col_data_last + 2).Borders.LineStyle = xlNone

End If

Next

Next


Variables
Code:
'''Row variable (not affected by data)

Dim row_data_start As Long

row_data_start = 5 'column "C" in 5th row

'''Row variable affected by data

Dim row_data_last As Long 'depends on data records

row_data_last = Cells(Rows.Count, "C").End(xlUp).Row

'''Column variable (not affected by data)

Dim col_data_start As Long

col_data_start = 5 'column "E" in 4th row

'''Column variable affected by data

Dim col_data_last As Long 'last header in 4th row

col_data_last = Cells(4, Columns.Count).End(xlToLeft).Column
 

Attachments

  • mrExcel 7.28.22.png
    mrExcel 7.28.22.png
    61.9 KB · Views: 4

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Forum statistics

Threads
1,215,470
Messages
6,124,990
Members
449,201
Latest member
Lunzwe73

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top