cell value mapping to another cell from sheet in VBA

mayaa_mmm

Board Regular
Joined
Jul 30, 2014
Messages
54
Office Version
  1. 2010
Platform
  1. Windows
NamesOutput
ArulCS
MalaCS
ShanCS
SelvSW
ManiSW
MuthuSW


I need to find the count of Column A .Examples Column A have count of 6 in worksheet. I need to divide the count of column A and assisgn the work between two names based on the another sheet
Assisgn
CS
SW

if the Count of column A is odd, EXample count is 5, It can assign the to name CS -3 times SW-2 times.

is it possible to code in VBA?
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Hi Mayaa,

Try This:
Code:
Sub Make_Output()
    Dim rng_A As Range
    Dim CntNms, dv, rm As Integer
    Set rng_A = Worksheets("Sheet1").Range("A:A")
    CntNms = WorksheetFunction.CountA(rng_A) - 1  'Count of names in column A
    dv = WorksheetFunction.Quotient(CntNms, 2) ' integer portion of a division
    rm = CntNms Mod 2  'remainder of a division
    
    If rm = 0 Then
        Range(Worksheets("Sheet1").Range("B2"), Worksheets("Sheet1").Range("B" & dv + 1)) = Worksheets("Sheet2").Range("A2").Value
        Range(Worksheets("Sheet1").Range("B" & dv + 2), Worksheets("Sheet1").Range("B" & dv + dv + 1)) = Worksheets("Sheet2").Range("A3").Value
    Else
        Range(Worksheets("Sheet1").Range("B2"), Worksheets("Sheet1").Range("B" & dv + 2)) = Worksheets("Sheet2").Range("A2").Value
        Range(Worksheets("Sheet1").Range("B" & dv + 3), Worksheets("Sheet1").Range("B" & dv + dv + 2)) = Worksheets("Sheet2").Range("A3").Value
    End If
    
End Sub
See attached too
 

Attachments

  • Sheets.jpg
    Sheets.jpg
    28.7 KB · Views: 53
Upvote 0
Hi Mayaa,

Try This:
Code:
Sub Make_Output()
    Dim rng_A As Range
    Dim CntNms, dv, rm As Integer
    Set rng_A = Worksheets("Sheet1").Range("A:A")
    CntNms = WorksheetFunction.CountA(rng_A) - 1  'Count of names in column A
    dv = WorksheetFunction.Quotient(CntNms, 2) ' integer portion of a division
    rm = CntNms Mod 2  'remainder of a division
   
    If rm = 0 Then
        Range(Worksheets("Sheet1").Range("B2"), Worksheets("Sheet1").Range("B" & dv + 1)) = Worksheets("Sheet2").Range("A2").Value
        Range(Worksheets("Sheet1").Range("B" & dv + 2), Worksheets("Sheet1").Range("B" & dv + dv + 1)) = Worksheets("Sheet2").Range("A3").Value
    Else
        Range(Worksheets("Sheet1").Range("B2"), Worksheets("Sheet1").Range("B" & dv + 2)) = Worksheets("Sheet2").Range("A2").Value
        Range(Worksheets("Sheet1").Range("B" & dv + 3), Worksheets("Sheet1").Range("B" & dv + dv + 2)) = Worksheets("Sheet2").Range("A3").Value
    End If
   
End Sub
See attached too

Really awesome it is working good as i wanted.. Brilliant Coding
 
Upvote 0

Forum statistics

Threads
1,223,750
Messages
6,174,290
Members
452,554
Latest member
Louis1225

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