PDA

View Full Version : Make a cicle



Rayman
03-16-2011, 10:41 AM
I have two Worksheets in a Workbook, a list of name is on Sheet 1 ,column "A" , in column "B" a list of number; in sheet 2 in column "C" i can have the same names of sheet 1 colum "A" or other names or nothing.

I need a macro wich for each name in sheet 2 column "C" if this name is = to a name in sheet 1 column "A" put in sheet 2 column "D" the corriponding number , if the name is different show a input box , if the name is "" go to next name.

"Example:

Sheet 1(present record)
Column A-----------Column B

A------------------------1
B------------------------2
C------------------------3
D------------------------4

------------------

Sheet 2
Column C ---------------Column D

" ">>>>>>>>>>>>>>>>>go to next name
New Name >>>>>>>>>>>InputBox
A>>>>>>>>>>>>>>>>>>>>1
D>>>>>>>>>>>>>>>>>>>>4



Thanks for your help

mdmackillop
03-16-2011, 12:51 PM
Welcome to VBAX,
You don't say what to do with the Input, but here's a start.

Option Explicit
Sub Naming()
Dim Rng1 As Range, rng2 As Range, c As Range, cel As Range
Set Rng1 = Sheets(2).Columns(3).SpecialCells(xlCellTypeConstants)
Set rng2 = Sheets(1).Columns(1)
For Each cel In Rng1
Set c = rng2.Find(cel)
If Not c Is Nothing Then cel.Offset(, 1) = c.Offset(, 1)
Next
For Each cel In Rng1
Set c = rng2.Find(cel)
If c Is Nothing Then InputBox "This name is not found", , cel
Next
End Sub

Rayman
03-16-2011, 02:29 PM
Welcome to VBAX,
You don't say what to do with the Input, but here's a start.

Option Explicit
Sub Naming()
Dim Rng1 As Range, rng2 As Range, c As Range, cel As Range
Set Rng1 = Sheets(2).Columns(3).SpecialCells(xlCellTypeConstants)
Set rng2 = Sheets(1).Columns(1)
For Each cel In Rng1
Set c = rng2.Find(cel)
If Not c Is Nothing Then cel.Offset(, 1) = c.Offset(, 1)
Next
For Each cel In Rng1
Set c = rng2.Find(cel)
If c Is Nothing Then InputBox "This name is not found", , cel
Next
End Sub




MANY THANKS, its works perfectly, and help me to undertstand how to make a cicle.
Regards

Rayman
03-16-2011, 03:05 PM
The input should write the user's input in the row with the name non found in column D sheet2

Rayman
03-16-2011, 03:23 PM
Perfect , input solved. Another Thanks you


Sub PrezziTotaliGiornaleMacchinari()

Dim RngPers As Range, rngPers2 As Range, P As Range, celPers As Range, RigheScritte As Range, LunghezzaFoglio As Integer, MyInput
Set RigheScritte = ActiveSheet.Cells(1, 1).CurrentRegion
LunghezzaFoglio = RigheScritte.Rows.Count

Set RngPers = Sheets("Giornale di Cantiere").Range("K4:K" & LunghezzaFoglio).SpecialCells(xlCellTypeConstants)
Set rngPers2 = Sheets("Elenchi").Columns(4)
For Each celPers In RngPers
Set P = rngPers2.Find(celPers)
If Not P Is Nothing Then celPers.Offset(, 3) = P.Offset(, 1)
Next
For Each celPers In RngPers
Set P = rngPers2.Find(celPers)
If P Is Nothing Then celPers.Offset(, 3).Value = InputBox("Non ho trovato questo nome!", , celPers)
Next
End Sub