Urgent Formula/Macros assitance

Eugene Hirdes

New Member
Joined
Jan 14, 2014
Messages
3
Hi,

I have an excel spreadsheet with over 70k lines in it for all the different countries(sheet1), it lists various costings for all the countries and the telecom providers which are within those countries. As shown below:

[TABLE="width: 517"]
<tbody>[TR]
[TD]Prefix[/TD]
[TD]Named Route Name[/TD]
[TD]Sell Rate[/TD]
[/TR]
[TR]
[TD="align: right"]7840[/TD]
[TD]Abkhazia Fixed[/TD]
[TD="align: right"]£0.13[/TD]
[/TR]
[TR]
[TD="align: right"]7940[/TD]
[TD]Abkhazia Mobile[/TD]
[TD="align: right"]£0.08[/TD]
[/TR]
[TR]
[TD="align: right"]79407[/TD]
[TD]Abkhazia Mobile - A-Mobile[/TD]
[TD="align: right"]£0.13[/TD]
[/TR]
[TR]
[TD="align: right"]79409[/TD]
[TD]Abkhazia Mobile - Aquafon[/TD]
[TD="align: right"]£0.15[/TD]
[/TR]
[TR]
[TD="align: right"]93[/TD]
[TD]Afghanistan Fixed[/TD]
[TD="align: right"]£0.16[/TD]
[/TR]
[TR]
[TD="align: right"]9375[/TD]
[TD]Afghanistan Mobile - At[/TD]
[TD="align: right"]£0.15[/TD]
[/TR]
[TR]
[TD="align: right"]9370[/TD]
[TD]Afghanistan Mobile - AWCC[/TD]
[TD="align: right"]£0.14[/TD]
[/TR]
[TR]
[TD="align: right"]9378[/TD]
[TD]Afghanistan Mobile - Etisalat[/TD]
[TD="align: right"]£0.12[/TD]
[/TR]
[TR]
[TD="align: right"]9377[/TD]
[TD]Afghanistan Mobile - MTN[/TD]
[TD="align: right"]£0.12[/TD]
[/TR]
[TR]
[TD="align: right"]9372[/TD]
[TD]Afghanistan Mobile - Roshan[/TD]
[TD="align: right"]£0.14[/TD]
[/TR]
[TR]
[TD="align: right"]9379[/TD]
[TD]Afghanistan Mobile - Roshan[/TD]
[TD="align: right"]£0.14[/TD]
[/TR]
[TR]
[TD="align: right"]355[/TD]
[TD]Albania Fixed[/TD]
[TD="align: right"]£0.12[/TD]
[/TR]
[TR]
[TD="align: right"]3554249[/TD]
[TD]Albania Fixed - AlbTel[/TD]
[TD="align: right"]£0.12[/TD]
[/TR]
[TR]
[TD="align: right"]3554250[/TD]
[TD]Albania Fixed - OLO[/TD]
[TD="align: right"]£0.12[/TD]
[/TR]
[TR]
[TD="align: right"]3554251[/TD]
[TD]Albania Fixed - OLO[/TD]
[TD="align: right"]£0.12[/TD]
[/TR]
[TR]
[TD="align: right"]3554252[/TD]
[TD]Albania Fixed - OLO[/TD]
[TD="align: right"]£0.12[/TD]
[/TR]
[TR]
[TD="align: right"]3554[/TD]
[TD]Albania Fixed - Tirana[/TD]
[TD="align: right"]£0.12[/TD]
[/TR]
[TR]
[TD="align: right"]35568[/TD]
[TD]Albania Mobile - AMC[/TD]
[TD="align: right"]£0.22[/TD]
[/TR]
[TR]
[TD="align: right"]35567[/TD]
[TD]Albania Mobile - Eagle[/TD]
[TD="align: right"]£0.18[/TD]
[/TR]
[TR]
[TD="align: right"]35566[/TD]
[TD]Albania Mobile - Plus[/TD]
[TD="align: right"]£0.23[/TD]
[/TR]
[TR]
[TD="align: right"]35569[/TD]
[TD]Albania Mobile - Vodafone[/TD]
[TD="align: right"]£0.15[/TD]
[/TR]
</tbody>[/TABLE]

Column A is the prefix(dialing code) Column b is the Country and the various suppliers and Column c is the cost - Now what I require is a formula to work out the Max value for both fixed and mobile rates, per country and this is to be done on sheet2. Below is an example of what it should look like:

Prefix is done away with and will only have 2 columns Named Route and Selling rate

Col A Col B
Named Route Selling Rate
[TABLE="width: 517"]
<tbody>[TR]
[TD]Abkhazia Fixed[/TD]
[TD="align: right"]£0.13[/TD]
[/TR]
</tbody>[/TABLE]
Abkhazia Mobile £0.15
Afghanistan Fixed £0.16
Afghanistan Mobile £0.14
Albania Fixed £0.12
Albania Mobile £0.23
etc etc till Zimbabwe

So if there is a formula or anything that could do this Automatically it would be greatly appreciated.
NOTE: I receive updated spreadsheets form my suppliers fortnightly and they sometime add new lines for countries or remove - so was thinking that the easiest would be to use the full range from row1 to 70K+, search for Abkhazia fixed and determine the cost then the same for the rest.....at this point I am about to pull out what little hair I have left- so any assistance or advice is welcome.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Try this

Code:
Sub GetMaxCostPercountry()
Dim rngMyRange As Range
Dim rngMyCell As Range
Dim lRangeRowDepth As Long
Dim lRangeRowDepth2 As Long
'find the depth of the description column
lRangeRowDepth = Cells(Rows.Count, 2).End(xlUp).Row
Set rngMyRange = Range("B2:B" & lRangeRowDepth)
For Each rngMyCell In rngMyRange
   'get fixed or mobile
   rngMyCell.Offset(0, 3).Value = IIf(InStr(1, rngMyCell.Value, "-") > 0, Trim(Left(rngMyCell.Value, (InStr(1, rngMyCell.Value, " -")))), rngMyCell.Value)
   DoEvents
   'build a country list
   rngMyCell.Offset(0, 2).Value = Trim(Replace(Replace(rngMyCell.Offset(0, 3).Value, "Mobile", ""), "Fixed", ""))
   DoEvents
   'take a copy of the price
   rngMyCell.Offset(0, 4).Value = rngMyCell.Offset(0, 1).Value
   
Next rngMyCell
    
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("D2:D" & lRangeRowDepth) _
        , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("C2:C" & lRangeRowDepth) _
        , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Sheet1").Sort
        .SetRange Range("A2:F" & lRangeRowDepth)
        .Header = xlGuess
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        
        .Apply
    End With
    Sheets("Sheet2").Select
    Selection.ClearContents
    
    Sheets("Sheet1").Select
    Columns("D:D").Select
    Selection.Copy
    Sheets("Sheet2").Select
    Range("a1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False
    ActiveSheet.Range("$A$2:$A$" & lRangeRowDepth).RemoveDuplicates Columns:=1, Header:=xlNo
    DoEvents
    lRangeRowDepth2 = Cells(Rows.Count, 1).End(xlUp).Row
    Set rngMyRange = Range("$A$2:$A$" & lRangeRowDepth2)
    For Each rngMyCell In rngMyRange
       rngMyCell.Offset(0, 1).Formula = "=IF(Vlookup(" & rngMyCell.Address & ",Sheet1!D2:F" & lRangeRowDepth & ",1,true)<>" & rngMyCell.Address & ",0,Vlookup(" & rngMyCell.Address & ",Sheet1!D2:F" & lRangeRowDepth & ",2,true))"
       DoEvents
       rngMyCell.Offset(0, 2).Formula = "=IF(Vlookup(" & rngMyCell.Address & ",Sheet1!D2:F" & lRangeRowDepth & ",1,true)<>" & rngMyCell.Address & ",0,Vlookup(" & rngMyCell.Address & ",Sheet1!D2:F" & lRangeRowDepth & ",3,true))"
       DoEvents
    Next rngMyCell
DoEvents
    
    Columns("B:C").Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False

'clear up
Sheets("Sheet1").Select
    Columns("D:F").Select
    Selection.ClearContents

End Sub

select the sheet with the provided data and run macro GetMaxCostPercountry

expects the first sheet is called Sheet1 and the second Sheet2

expects data on sheet1 to start at row 2
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

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