+ Reply to Thread
Results 1 to 7 of 7

Calculate total space usage from spreadsheet

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-21-2013
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    258

    Calculate total space usage from spreadsheet

    Good Morning All,

    I wrote the below code to try calculate the total amount of space used on an FTP site.
    I have a list of all the different folders and the space they take up is in column 'B'. However the amount of space is followed by a 'KB' or 'MB' or 'GB'. So What I'd like to do is calculate the total amount of space in Gigabytes. I'm not sure what data types to set everything as for this in order to get this to work.
    The Macro runs without any errors, but only returns a 0.

    Any help would be greatly appreciated.

    Cheers

    R

    Sub StorageTotal()
    Dim FTP As Worksheet
    Dim RowNo As Long, LastRow As Long
    Dim Total As Integer
    Dim GB As String, MB As String, KB As String
    Dim GBRT As Double, MBRT As Double, KBRT As Double
    Dim TotalCalc As Double
    
    Set FTP = ThisWorkbook.Worksheets("FTP Register")
    
        With FTP
            LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
                For RowNo = 2 To LastRow
                
                   If InStr(1, FTP.Cells(RowNo, "B"), "GB", vbTextCompare) = "1" Then
                    GB = FTP.Cells(RowNo, "B")
                    GB = Right(GB, Len(GB) - 2)
                    GBRT = GBRT + GB
                    
                   ElseIf InStr(1, FTP.Cells(RowNo, "B"), "MB", vbTextCompare) = "1" Then
                    MB = FTP.Cells(RowNo, "B")
                    MB = Right(MB, Len(MB) - 2)
                    MBRT = MBRT + MB
                    
                   ElseIf InStr(1, FTP.Cells(RowNo, "B"), "KB", vbTextCompare) = "1" Then
                    KB = FTP.Cells(RowNo, "B")
                    KB = Right(KB, Len(KB) - 2)
                    KBRT = KBRT + KB
                   
                   ElseIf InStr(1, FTP.Cells(RowNo, "B"), "Empty", vbTextCompare) = "1" Then
                   End If
                Next
             
             TotalCalc = GBRT + (MBRT / 1024) + ((KBRT / 1024) / 1024)
             
             FTP.Cells(17, "L") = TotalCalc
        End With
            
    End Sub

  2. #2
    Forum Contributor
    Join Date
    01-21-2013
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    258

    Re: Calculate total space usage from spreadsheet

    Updated but still not working

    Sub StorageTotal()
    Dim FTP As Worksheet
    Dim RowNo As Long, LastRow As Long
    Dim Total As Integer
    Dim GB As String, MB As String, KB As String
    Dim GBCon As Double, MBCon As Double, KBCon As Double
    Dim GBRT As Double, MBRT As Double, KBRT As Double
    Dim TotalCalc As Double
    
    Set FTP = ThisWorkbook.Worksheets("FTP Register")
    
        With FTP
            LastRow = FTP.Cells(.Rows.Count, "A").End(xlUp).Row
                For RowNo = 2 To LastRow
                
                   If InStr(1, FTP.Cells(RowNo, "B"), "GB", vbTextCompare) = "1" Then
                    GB = FTP.Cells(RowNo, "B")
                    GB = Right(GB, Len(GB) - 2)
                    GBCon = Val(GB)
                    GBRT = GBRT + GBCon
                    
                   ElseIf InStr(1, FTP.Cells(RowNo, "B"), "MB", vbTextCompare) = "1" Then
                    MB = FTP.Cells(RowNo, "B")
                    MB = Right(MB, Len(MB) - 2)
                    MBCon = Val(MB)
                    MBRT = MBRT + MBCon
                    
                   ElseIf InStr(1, FTP.Cells(RowNo, "B"), "KB", vbTextCompare) = "1" Then
                    KB = FTP.Cells(RowNo, "B")
                    KB = Right(KB, Len(KB) - 2)
                    KBCon = Val(KB)
                    KBRT = KBRT + KBCon
                   
                   ElseIf InStr(1, FTP.Cells(RowNo, "B"), "Empty", vbTextCompare) = "1" Then
                   End If
                Next
             
             TotalCalc = GBRT + (MBRT / 1024) + ((KBRT / 1024) / 1024)
             
             FTP.Cells(17, "L") = TotalCalc
        End With
    End Sub

  3. #3
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Calculate total space usage from spreadsheet

    Can you attach a sample file for us to 'play' with..

    I am thinking you could incorporate autofilter then change each value to a common denominator (GB).. you could change the actual value or use a helper column..

  4. #4
    Forum Contributor
    Join Date
    01-21-2013
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    258

    Re: Calculate total space usage from spreadsheet

    Here ya go
    Attached Files Attached Files

  5. #5
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Calculate total space usage from spreadsheet

    maybe so
    Sub StorageTotal22()
    Dim r As Range
    Dim GBRT As Double, MBRT As Double, KBRT As Double
    With ThisWorkbook.Worksheets("FTP Register")
        For Each r In .Range("B1", .Cells(Rows.Count, 2).End(xlUp))
            Select Case True
                Case InStr(r, "GB"): GBRT = GBRT + Val(r)
                Case InStr(r, "MB"): MBRT = MBRT + Val(r)
                Case InStr(r, "KB"): KBRT = KBRT + Val(r)
            End Select
        Next r
        .Cells(17, "L") = GBRT + (MBRT / 1024) + ((KBRT / 1024) / 1024)
    End With
    End Sub
    Last edited by nilem; 03-07-2014 at 07:02 AM.

  6. #6
    Forum Contributor
    Join Date
    01-21-2013
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    258

    Re: Calculate total space usage from spreadsheet

    Cheers Dude!

    Is there anyway I can shorten the total to .00 decimal places, Then stick a Gb on the end?

  7. #7
    Forum Contributor
    Join Date
    01-21-2013
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    258

    Re: Calculate total space usage from spreadsheet

    It's cool, I got it. Cheers for all your help!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 3
    Last Post: 03-06-2014, 12:48 AM
  2. Replies: 8
    Last Post: 08-10-2009, 04:21 PM
  3. Total Usage. Date Problem
    By treva26 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-31-2008, 03:02 AM
  4. excel-hrs spreadsheet-work 8:15 - 5:30 (how calculate total hrs?)
    By Harris in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-14-2006, 04:35 PM
  5. [SOLVED] Any Tricks to decreasing Workbook size (disk space usage)?
    By Bruce in forum Excel General
    Replies: 3
    Last Post: 08-16-2005, 10:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1