S
Suh Suk Ho
Dear Colleagues;
Thank you for the answer last time about selecting a range even though I'm
still stuck with it and sitting on it.
I'm trying to select a cell right next to a cell in a named range as in the
following context;
For each cell in NamedRange
If cell.Value= A_Value_from_a_ListBox Then
---> Select a CELL(or a Range) right next to cell
End If
Next
I tried the followings and they all didn't work;
- cell.Offset(0,1).Select
- ActiveCell.Offset(ActiveCell.Row, ActiveCell.Column + 1).Select
- ActiveCell.Offset(0, 1).Select
And there's nothing wrong with the NamedRange.
The code at the bottom is the code I'm having trouble with.
Please help.
And what is that ActiveCell anyway? Isn't that supposed to be the one that
is being, what do call it, stepped through for example by For.. Next loop?
As you can see, my level of VBA is very poor, even though I've been learning
quite a while. Please help, please!
Yours Sincerely,
Suh, Suk Ho
Private Sub CommandButton1_Click()
'ÀÏ´Ü ¼¼ºÎ»ç¾çÀÌ µé¾îÀÖ´Â ³»¿ëÀ» ¸ðµÎ Áö¿î´Ù.
Dim RowCount As Single
'¿©±â¿¡ ¸¸¾à¿¡ a25¿¡ ¾Æ¹«·± ³»¿ëÀÌ µé¾îÀÖÁö ¾Ê´Ù¸é °Ç³Ê ¶Ú´Ù.
If Sheets("Quotation").Range("a25").Value <> "" Then
RowCount = Sheets("Quotation").Range("a25").CurrentRegion.Rows.Count
Sheets("Quotation").Range("a25:j" & 25 + RowCount & "").Select
Selection.Delete Shift:=xlUp
MsgBox "Why in the hell are you here"
End If
Dim Cell_A25 As Single 'a25¹ø ¼¿¹øÈ£
Cell_A25 = 25
For i = 0 To frmModelSelect.lboxRight.ListCount - 1
With Sheets("Quotation")
.Range("a" & Cell_A25 & ":I" & Cell_A25 & "").Select
Selection.Insert Shift:=xlDown
'¼¿À» Æ÷¸Ë½ÃŲ´Ù.
.Range("a" & Cell_A25 & ":d" & Cell_A25 & "").Select
With Selection
.WrapText = True
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = True
End With
.Range("H" & Cell_A25 & ":I" & Cell_A25 & "").Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = True
.NumberFormatLocal = "$#,##0.00"
End With
End With '½¬Æ®
' ¸®½ºÆ®¹Ú½ºÀÇ ³»¿ëÀ» ²¨³»¼ ±× ³»¿ëÀ» Specifications ½¬Æ®ÀÇ ³»¿ë°ú
ºñ±³ÇÏ¿©, ä¿ö³Ö´Â´Ù.
' 1. SpecificationÀÇ ModelName ¹üÀ§¿¡¼ ¸®½ºÆ® ¹Ú½ºÀÇ ³»¿ëÀ» ã¾Æ¼, ±×
³»¿ëÀÇ ¹Ù·Î ¿·ÄÀÇ ³»¿ëÀ» º¹»çÇؼ
For Each cell In Sheets("Specifications").Range("ModelName")
If cell.Value = frmModelSelect.lboxRight.List(i) Then
MsgBox "cell.value : " & cell.Value
MsgBox "frmModelSelect.lboxRight.List(i) : " &
frmModelSelect.lboxRight.List(i)
MsgBox "cell.Offset(0, 1).Value : " & cell.Offset(0, 1).Value
MsgBox "ActiveCell.Value :" & ActiveCell.Value
' Sheets("Specifications").Range("" & ActiveCell.Offset(0, 1) & ":"
& ActiveCell.Offset(0, 5) & "").Select
'Sheets("Specifications").Range(Cells(ActiveCell.Row,
ActiveCell.Column + 1), Cells(ActiveCell.Row, ActiveCell.Column + 5)).Select
'Sheets("Specifications").Range(Cells(cell.Row, cell.Column + 1),
Cells(cell.Row, cell.Column + 5)).Select
MsgBox "¼¿ ¿: " & ActiveCell.Row & "¼¿ Çà : " & ActiveCell.Column &
""
cell.Offset(0, 1).Select
' ActiveCell.Offset(ActiveCell.Row, ActiveCell.Column + 1).Select
Selection.Copy
Sheets("Quotation").Range("A" & Cell_A25 & "").Select
ActiveSheet.Paste
Application.CutCopyMode = False
End If
Next
Cell_A25 = Cell_A25 + 1
Next
Unload Me
End Sub
Thank you for the answer last time about selecting a range even though I'm
still stuck with it and sitting on it.
I'm trying to select a cell right next to a cell in a named range as in the
following context;
For each cell in NamedRange
If cell.Value= A_Value_from_a_ListBox Then
---> Select a CELL(or a Range) right next to cell
End If
Next
I tried the followings and they all didn't work;
- cell.Offset(0,1).Select
- ActiveCell.Offset(ActiveCell.Row, ActiveCell.Column + 1).Select
- ActiveCell.Offset(0, 1).Select
And there's nothing wrong with the NamedRange.
The code at the bottom is the code I'm having trouble with.
Please help.
And what is that ActiveCell anyway? Isn't that supposed to be the one that
is being, what do call it, stepped through for example by For.. Next loop?
As you can see, my level of VBA is very poor, even though I've been learning
quite a while. Please help, please!
Yours Sincerely,
Suh, Suk Ho
Private Sub CommandButton1_Click()
'ÀÏ´Ü ¼¼ºÎ»ç¾çÀÌ µé¾îÀÖ´Â ³»¿ëÀ» ¸ðµÎ Áö¿î´Ù.
Dim RowCount As Single
'¿©±â¿¡ ¸¸¾à¿¡ a25¿¡ ¾Æ¹«·± ³»¿ëÀÌ µé¾îÀÖÁö ¾Ê´Ù¸é °Ç³Ê ¶Ú´Ù.
If Sheets("Quotation").Range("a25").Value <> "" Then
RowCount = Sheets("Quotation").Range("a25").CurrentRegion.Rows.Count
Sheets("Quotation").Range("a25:j" & 25 + RowCount & "").Select
Selection.Delete Shift:=xlUp
MsgBox "Why in the hell are you here"
End If
Dim Cell_A25 As Single 'a25¹ø ¼¿¹øÈ£
Cell_A25 = 25
For i = 0 To frmModelSelect.lboxRight.ListCount - 1
With Sheets("Quotation")
.Range("a" & Cell_A25 & ":I" & Cell_A25 & "").Select
Selection.Insert Shift:=xlDown
'¼¿À» Æ÷¸Ë½ÃŲ´Ù.
.Range("a" & Cell_A25 & ":d" & Cell_A25 & "").Select
With Selection
.WrapText = True
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = True
End With
.Range("H" & Cell_A25 & ":I" & Cell_A25 & "").Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = True
.NumberFormatLocal = "$#,##0.00"
End With
End With '½¬Æ®
' ¸®½ºÆ®¹Ú½ºÀÇ ³»¿ëÀ» ²¨³»¼ ±× ³»¿ëÀ» Specifications ½¬Æ®ÀÇ ³»¿ë°ú
ºñ±³ÇÏ¿©, ä¿ö³Ö´Â´Ù.
' 1. SpecificationÀÇ ModelName ¹üÀ§¿¡¼ ¸®½ºÆ® ¹Ú½ºÀÇ ³»¿ëÀ» ã¾Æ¼, ±×
³»¿ëÀÇ ¹Ù·Î ¿·ÄÀÇ ³»¿ëÀ» º¹»çÇؼ
For Each cell In Sheets("Specifications").Range("ModelName")
If cell.Value = frmModelSelect.lboxRight.List(i) Then
MsgBox "cell.value : " & cell.Value
MsgBox "frmModelSelect.lboxRight.List(i) : " &
frmModelSelect.lboxRight.List(i)
MsgBox "cell.Offset(0, 1).Value : " & cell.Offset(0, 1).Value
MsgBox "ActiveCell.Value :" & ActiveCell.Value
' Sheets("Specifications").Range("" & ActiveCell.Offset(0, 1) & ":"
& ActiveCell.Offset(0, 5) & "").Select
'Sheets("Specifications").Range(Cells(ActiveCell.Row,
ActiveCell.Column + 1), Cells(ActiveCell.Row, ActiveCell.Column + 5)).Select
'Sheets("Specifications").Range(Cells(cell.Row, cell.Column + 1),
Cells(cell.Row, cell.Column + 5)).Select
MsgBox "¼¿ ¿: " & ActiveCell.Row & "¼¿ Çà : " & ActiveCell.Column &
""
cell.Offset(0, 1).Select
' ActiveCell.Offset(ActiveCell.Row, ActiveCell.Column + 1).Select
Selection.Copy
Sheets("Quotation").Range("A" & Cell_A25 & "").Select
ActiveSheet.Paste
Application.CutCopyMode = False
End If
Next
Cell_A25 = Cell_A25 + 1
Next
Unload Me
End Sub