populating cells using data from a different worksheet
Hi Divyanshu
The following code should do what you want or at least give you a
starting point to work with the code to get your desired results.
Open up VBE (Alt and F11)
Add a userform from the "Insert menu" then add a single command button
to the form the "toolbox" then in the code view paste the following
code
Option Explicit
Dim MyCell, MyRng As Range
Dim MyStr As String
Dim MyRow As Integer
Private Sub CommandButton1_Click()
Sheets(1).Activate 'Set the active sheet to sheet 1
MyRow = [A1].End(xlDown).Row 'Find last used row in the A Column
Set MyRng = Range("A1", "U" & MyRow) 'Set the range of cells you want
to change
For Each MyCell In MyRng 'Start to move through each cell in your
range
MyStr = MyCell.Address 'Take the cell address and pass it to a
string
MyStr = Mid(MyStr, 2, 1) 'Define the column letter from the
string
Select Case MyCell.Value 'Set the conditions for changing
the cell value
Case 0 To 3
MyCell.Value = MyStr & "-Low"
Case 4 To 7
MyCell.Value = MyStr & "-Med"
Case 8 To 11
MyCell.Value = MyStr & "-Hi"
End Select
Next MyCell 'Move on to the next cell in your range
End Sub
I would run this on a test sheet first just to see if this is what you
are after. If you want a better idea of how the code works when you
have pasted it press the F8 key to run the code line by line you will
be able to minimise VBE and see the effect on the cells as you move
through the code.
Hope this helps you out
S
|