Divide or multiply string value

Vincent88

Active Member
Joined
Mar 5, 2021
Messages
382
Office Version
  1. 2019
Platform
  1. Windows
  2. Mobile
Hi All, Please help !
What should I do if I want to have a string value divide by 2 (or *0.5) and use its value result to add to another string.
I mean if the strampm result is 3, then divide by 2 to get value result 1.5. Then add this result to another string strday.

dim strampm as string, strday as string
strampm = Application.Sum(Application.CountIfs(rgLookUp, myArrayampm))

then add the result to this string

strday = Application.Sum(Application.CountIfs(rgLookUp, myArrayd))
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Why string values when they are clearly numbers?
And why are you using SUM with COUNTIFS? Would it be prudent to instead use SUMIFS here instead?

I think it would be helpful to see an example of exactly what the data you are working with looks like, and what your expected result should be.

MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
 
Upvote 0
Hi Joe4,
I need the string value strampm be divided by 2, then add this result to strlve adn strday.

AgentProposal_Roster0728_0824.xlsm
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKAL
1MDateAttendance27-Aug28-Aug29-Aug30-Aug31-Aug1-Sep2-Sep3-Sep4-Sep5-Sep6-Sep7-Sep8-Sep9-Sep10-Sep11-Sep12-Sep13-Sep14-Sep15-Sep16-Sep17-Sep18-Sep19-Sep20-Sep21-Sep22-Sep23-Sep24-Sep25-Sep26-Sep27-Sep28-Sep29-Sep30-Sep1-Oct
2DateSummary(5)(4)(3)(2)(1)12345678910111213141516171819202122232425262728293031
3Cat MT:21 L:0 D:4 E:0 N:1GGGGGD2D3D4DAMNN
4Kitty MT:21 L:1 D:3 E:0 N:0DDVLPMDGG
5Lucy HT:21 L:1 D:1 E:1 N:0EALAMPME
6James ST:21 L:2 D:3 E:0 N:0D4ALVLD4ALAL
7Vincy WT:21 L:1 D:3 E:0 N:0DDDALNDDDD
8Eric QT:21 L:1 D:1 E:1 N:0DDVLDEE
9Howard YT:21 L:1 D:1 E:0 N:0DALD
10Icy ZT:21 L:0 D:1 E:0 N:1DDNDD
11Zita CT:21 L:1 D:1 E:0 N:1VLDNVLD
12Derk OT:21 L:0 D:4 E:0 N:1DDDDDNDDDD
13Yiko FT:21 L:1 D:2 E:0 N:0DDDALDD
14Fanny PT:21 L:1 D:4 E:0 N:0DDDDDVLDDDD
202109
Cells with Data Validation
CellAllowCriteria
H3:AL14List=ShiftcodeNew
A3:A13List=HelpAgent
A14List=HelpAgent

VBA Code:
Sub vSum8()

    Application.DisplayStatusBar = False
    Application.EnableEvents = False
    Application.ScreenUpdating = False


    Dim rngg As Range
    Dim rnggRow As Range
    Dim i As Range
    Dim lastRow As Long
    Dim lastcol As Long
    Dim rnggCol As Range, rng1Row As Range
    Dim vDayB As Date, vDayE As Date
    Dim vColumnB As Range, vColumnE As Range
    
      
    ActiveWindow.ScrollColumn = 2
    
    lastRow = Cells(Rows.Count, "A").End(xlUp).Row
    lastcol = Cells(1, Columns.Count).End(xlToLeft).Column
    Set rngg = Range(Cells(1, 1), Cells(lastRow, lastcol))
    Set rnggCol = rngg.Columns(2).Cells(3).Resize(lastRow - 2, 1)
    
  
            
    
    For Each i In rnggCol
        'Set rnggColRow = rnggCol.Cells(i.Row - 2).Resize(1, vColumnE.Column - 1)
        Dim strtot As String, strlve As String, _
            strday As String, streve As String, strnte As String
        Dim strampm As String
        
        Dim myArrayd As Variant, myArrayl As Variant, myArrayampm As Variant
            myArrayd = Array("D", "D1", "D2", "D3", "D4", "G")
            myArrayl = Array("AL", "VL")
            myArrayampm = Array("AM", "PM")
            

            
            Set rng1Row = Range(Cells(1, 3), Cells(1, lastcol))
            vDayB = CDate(Format(ActiveSheet.Name, "0000-00"))
            vDayE = DateAdd("m", 1, vDayB) - 1
            Set vColumnB = rng1Row.Find(vDayB, , xlFormulas)
            Set vColumnE = rng1Row.Find(vDayE, , xlFormulas)
            
        Dim rgLookUp As Range
            Set rgLookUp = Range(i.Cells(, vColumnB.Column - 1), i.Cells(, vColumnE.Column - 1))
  
        Dim vLastRowHo As Long
        
        vLastRowHo = Worksheets("Data").Cells(Rows.Count, "A").End(xlUp).Row
        HolidayList = Worksheets("Data").Range("A2:A" & vLastRowHo).Value
        strtot = Application.NetworkDays(vDayB, vDayE, HolidayList)
        
        strampm = Evaluate("Application.Sum(Application.CountIfs(rgLookUp, myArrayampm))*0.5")
                Debug.Print strampm
                          
                        
        strlve = Application.Sum(Application.Sum(Application.CountIfs(rgLookUp, myArrayl)), strampm)
                
                
        strday = Application.Sum(Application.Sum(Application.CountIfs(rgLookUp, myArrayd)), strampm)
        

        streve = Application.CountIf(rgLookUp, "E")

        strnte = Application.CountIf(rgLookUp, "N")
 
        i = "T:" & strtot & " L:" & strlve & " D:" _
            & strday & " E:" & streve & " N:" & strnte
    Next i
    
    'CONDITIONAL FORMATTING CELL B TO HIGHLIGHT FONT COLOR
        If Application.Sum(strlve, strday, streve, strnte) > strtot Then
            i.Font.Color = vbRed
    
        ElseIf Application.Sum(strlve, strday, streve, strnte) < strtot Then
            i.Font.Color = vbGreen
        Else
            i.Font.Color = vbBlack
        End If
        
    Application.DisplayStatusBar = True
    Application.EnableEvents = True
    Application.ScreenUpdating = True

End Sub
 
Upvote 0
I need the string value strampm be divided by 2, then add this result to strlve adn strday.
I don't know what those are, in looking at your sheet.
Is that the data you are working with initially?
What should the expect result then look like?

Using the data posted, please walk us through an example, step-by-step, so we can understand and follow your logic.
 
Upvote 0
Hi Joe4, I searched this query in the net and eventully I need to make strampm as Double (not string) to make it works. Thanks.
 
Upvote 0

Forum statistics

Threads
1,215,352
Messages
6,124,453
Members
449,161
Latest member
NHOJ

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